home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / lib / mntlib44.zoo / mntlib / dup.c < prev    next >
C/C++ Source or Header  |  1994-03-01  |  783b  |  45 lines

  1. /* from Dale Schumacher's dLibs library */
  2.  
  3. /* will have to be adjusted at some time ++jrb */
  4. /* use with caution, TOS 1.4 still has double re-direction bug! */
  5.  
  6. #include <stddef.h>
  7. #include <fcntl.h>
  8. #include <errno.h>
  9. #include <mintbind.h>
  10. #include <unistd.h>
  11. #include "lib.h"
  12.  
  13. extern int __mint;
  14.  
  15. int
  16. dup(handle)
  17.     int handle;
  18. {
  19.     register int rv;
  20.     long flags;
  21.  
  22.     if (__mint)
  23.         rv = (int)Fcntl(handle, (long)0, F_DUPFD);
  24.     else
  25.         rv = (int)Fdup(handle);
  26.  
  27.     if (rv < (__SMALLEST_VALID_HANDLE)) {
  28.         errno = -rv;
  29.         rv = -1;
  30.     }
  31.     else
  32.     {
  33.         if (__OPEN_INDEX(rv) < __NHANDLES) {
  34.             __open_stat[__OPEN_INDEX(rv)] =
  35.                 __open_stat[__OPEN_INDEX(handle)];
  36.         }
  37.         if (__mint) {
  38.             flags = (long)Fcntl(rv, (long)0, F_GETFD);
  39.             (void)Fcntl(rv, flags & ~FD_CLOEXEC, F_SETFD);
  40.         }
  41.     }
  42.     return(rv);
  43. }
  44.  
  45.